#include <iostream>
#include "contacts.pb.h"

int main()
{
    std::string peoplestr;

    // 序列化
    {
        contacts::PeopleInfo people;
        people.set_name("Alice");
        people.set_age(18);

        if (!people.SerializeToString(&peoplestr))
        {
            std::cerr << "SerializeToString failed." << std::endl;
            return -1;
        }

        std::cout << "Serialized sucessed..." << std::endl;
        std::cout << "Serialized data: " << peoplestr << std::endl;
    }

    // 反序列化
    {
        contacts::PeopleInfo people;
        if (!people.ParseFromString(peoplestr))
        {
            std::cerr << "ParseFromString failed." << std::endl;
            return -1;
        }

        std::cout << "Deserialize sucessed..." << std::endl;
        std::cout << "Name: " << people.name() << std::endl;
        std::cout << "Age: " << people.age() << std::endl;
    }

    return 0;
}